# from multiprocessing import Process
# import time
# class Myprocess(Process):
#     def __init__(self,num):
#         super().__init__()
#         # super(Myprocess,self).__init__()
#         self.num=num
#     def run(self):
#         time.sleep(1)
#         print(self.is_alive())
#         print("第 %s 个进程的进程号是：%s" %(self.num,self.pid),time.ctime())
#         print("------------")
# if __name__ == '__main__':
#     p_list=[]
#     for i in range(10):
#         p = Myprocess(i)
#         p_list.append(p)
#         p.start()
#     for p in p_list:
#         p.join()
#     print("所有进程运行结束！！！！！")
# ___________进程队列Queue___________________

# from multiprocessing import Process,Queue
# import time
# def foo(q):
#     time.sleep(1)
#     q.put(6776)
#     q.put({"name":"张三"})
#
# if __name__ == '__main__':
#     q = Queue()
#     p=Process(target=foo,args=(q,))
#     p.start()
#     print(q.get())
#     print(q.get_nowait())
#     print(q.get(block=False))

# -----------------管道通信Pipe----------------
# from multiprocessing import Process, Pipe
# import time
# import os
# def f(conn):
#     conn.send([12,{"name":"子豪"},"hello"])
#     date=conn.recv()
#     print("父亲发的消息是",date,time.ctime())
#     conn.close()
#     print("子进程进程号%s,子进程拿到的数据ID %s："%(os.getpid(),id(conn)))
#
# if __name__ == '__main__':
#     parent_conn,child_conn=Pipe()
#     p =Process(target=f,args=(child_conn,))
#     p.start()
#     sunsend=parent_conn.recv()
#     print("儿子发消息是：",sunsend,time.ctime())
#     parent_conn.send("儿子，你好")
#     parent_conn.close()
#     print("父进程进程号%s，父进程拿到的数据ID %s：" %(os.getpid(),id(parent_conn)))
#     p.join()

# --------进程同步-------
'''加锁的部分完全是串行的'''
from  multiprocessing import Process,Lock
import time
def f(l,i):
    l.acquire()
    time.sleep(1)
    print("hello " ,i)
    l.release()
if __name__ == '__main__':
    lock =Lock()
    for num in range(10):
        Process(target=f,args=(lock,num)).start()
